﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bluyel.Core;

namespace Bluyel_Samples_VS10
{
    /// <summary>
    /// Code samples to see how to create types: all or to define exactly types.
    /// 
    /// To create data, you need to define built-in types.
    /// Its a way to control how type of data you can create in the application.
    /// 
    /// If you define all built-in types, you can create all type of data.
    /// </summary>
    public class Sample_Types
    {
        //---------------------------------------------------------------------
        /// <summary>
        /// Create all needed types by hand.
        /// </summary>
        public  void DefineAllTypesFindCheck()
        {
            Console.WriteLine("\n----Define, Find and check type:\n");

            BluyelCore core = new BluyelCore();

            // define basics types: int, double, string and bool
            core.TypeBuilder.DefineTypeInt();
            core.TypeBuilder.DefineTypeDouble();
            core.TypeBuilder.DefineTypeString();
            core.TypeBuilder.DefineTypeBool();

            core.TypeBuilder.DefineTypeStruct();

            core.TypeBuilder.DefineTypePhy(TypePhyQuantity.Length);

            // find the type int by the name
            IType typeIntFind = core.TypeFinder.FindTypeByName("int");
            Console.WriteLine("FindTypeByName('int'): " + typeIntFind.Name);

            // find the type int by the name, using the defined name
            IType typeIntFindName = core.TypeFinder.FindTypeByName(TypeDef.TypeIntName);
            Console.WriteLine("FindTypeByName(TypeDef.TypeIntName): " + typeIntFind.Name);

            // find the type int by the id
            IType typeIntFindId = core.TypeFinder.FindTypeById(TypeDef.TypeIntId);
            Console.WriteLine("FindTypeByName(TypeDef.TypeIntId): " + typeIntFind.Name);

            // check if the type is an int type: return true
            bool res = core.TypeFinder.IsTypeInt(typeIntFind);
            Console.WriteLine("IsTypeInt(typeIntFind)?:" + res);

            // check if the type is an int type: return false
            res = core.TypeFinder.IsTypeString(typeIntFind);
            Console.WriteLine("IsTypeString(typeIntFind)?:" + res);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create all types with one line.
        /// </summary>
        public  void DefineAllTypesWithSingleLine()
        {
            Console.WriteLine("\n----Define all types:\n");

            BluyelCore core = new BluyelCore();

            // with this single line, you create all availables types in the core
            core.TypeBuilder.DefineAllTypes();

            // you can create now data with any available type in the core:
            // int, string, double, bool, struct, Physical qty Length, LOVString,...


            // get the list of types (to display it,...)
            IEnumerable<IType> listType= core.TypeFinder.ListType;
            Console.WriteLine("Types defined count: " + listType.Count() + "\n");
            foreach (IType type in listType)
                Console.WriteLine(type.Id + " " + type.Name);
        }


    }
}
